/**
 * jims
 */
package com.jims.master.modules.patient.myRecord.service;

import com.jims.master.common.service.CrudService;
import com.jims.master.modules.patient.myRecord.dao.CasePrescriptionDetailsDao;
import com.jims.master.modules.patient.myRecord.entity.CasePrescription;
import com.jims.master.modules.patient.myRecord.entity.CasePrescriptionDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


/**
 * 同步his处方详情Service
 * @author chent
 * @version 2017-09-20
 */
@Service
@Transactional(readOnly = true)
public class CasePrescriptionDetailsService extends CrudService<CasePrescriptionDetailsDao, CasePrescriptionDetails> {
	@Autowired
	private CasePrescriptionService casePrescriptionService;

	/**
	 * 根据clinicId得到处方详细信息
	 * @param clinicId
	 * @author chent
	 * @return
	 */
	public List<CasePrescriptionDetails> getCasePrescriptionList(String clinicId){
		List<CasePrescriptionDetails> casePrescriptionList = new ArrayList();
		//根据clinicId获取处方主表信息
		List<CasePrescription> prescriptionList = casePrescriptionService.getByClinicId(clinicId);
		for (int i =0; i<prescriptionList.size();i++){
			//处方主表Id
			String applyId = prescriptionList.get(i).getId();
			//根据处方主表Id得到处方详细信息
			List<CasePrescriptionDetails> prescriptionDetailsList = dao.getPrescriptionDetailsList(applyId);
			for (int j =0; j<prescriptionDetailsList.size();j++){
				casePrescriptionList.add(prescriptionDetailsList.get(j));
			}
		}
		return casePrescriptionList;
	}
	
}